from django.shortcuts import render_to_response

class AutoRenderMiddleware:
    """
    Doc to write
    """
    def process_view(self, request, view_func, view_args, view_kwargs):
        from django.template import RequestContext
        
        response = view_func(request, *view_args, **view_kwargs)
        
        try:
            template = response['template']
            return render_to_response(template.replace('.', '/') + '.html', response['data'], context_instance=RequestContext(request))
        except KeyError, AttributeError:
            return response